package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.domain.db.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface LogMapper extends BaseMapper<Log> {

    @Select("SELECT COUNT(distinct user_id) FROM tb_log WHERE TYPE=#{type} AND log_time=#{today}")
    Integer selectByType(@Param("type") String type,@Param("today") String today);//根据传入的类型和日期查询今日的数据

    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE  log_time=#{today}")
    Integer selectNumActive(String today);//今日活跃用户数

    @Select("SELECT  COUNT(DISTINCT user_id) FROM tb_log WHERE log_time=#{today} AND user_id IN (\n" +
            "  SELECT user_id FROM tb_log WHERE log_time=#{yesterday} AND TYPE='0102'\n" +
            ")\n")
    Integer selectNumRetention1d(@Param("today") String today,@Param("yesterday") String yesterday);//次日留存
}